#ifndef __ELAPSED_TIME_H__
#define __ELAPSED_TIME_H__
#include <stdio.h>
#include <iostream>
#include <sstream>
#include "time/gettickcount.h"
#include "phlogger.h"

class ElapsedTime
{
public:
	ElapsedTime(const char* szfunction)
		:m_szFunction(szfunction)
	{
#if defined(DEBUG) || defined(_DEBUG)
		m_start_time = gettickcount();
#endif
	}

	virtual ~ElapsedTime()
	{
#if defined(DEBUG) || defined(_DEBUG)
		std::ostringstream oss;
		oss << "[time] called " << m_szFunction << ", elapsed time: " << (gettickcount()-m_start_time) << " ms";
	#ifdef WIN32
        WriteLog(LOG_ANOLE, "%s", oss.str().c_str());
		oss << "\r\n";
		std::cerr << oss.str();
		OutputDebugStringA(oss.str().c_str());
	#else
		oss << "\n";
		std::cerr << oss.str();
	#endif
#endif
	}

private:
	int m_flag;
    std::string m_szFunction;
	uint64_t m_start_time;
};

#define PARAM_FUNC			__FUNCTION__

#define ELAPSEDTIME_LOG1(x)	ElapsedTime object(x)

#define ELAPSEDTIME_LOG		ELAPSEDTIME_LOG1(PARAM_FUNC)

#endif